package com.wanghongli.week2house.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyWebMvcConfig implements WebMvcConfigurer {
    /**
     * 文件上传处理
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/img/**").addResourceLocations("file:D://pic//");
    }

    /**
     * 拦截器
     */
   /* @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration patterns = registry.addInterceptor(new UrlInterceptor()).addPathPatterns("/**").excludePathPatterns("/*.js").excludePathPatterns("/*.css");
        System.out.println(patterns);
    }*/

    /**
     * 跨域访问
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("*")
                .maxAge(3600);
    }
}
